
// This is just a random toy converting some Python code to Fan.
// TODO Delete this file.

//import time
//import re

class TailGrep {

	//def follow(fname):
	//    f = file(fname)
	//    f.seek(0,2) # go to the end
	//    while True:
	//        l = f.readline()
	//        if not l: # no data
	//            time.sleep(.1)
	//        else:
	//            yield l

	|->Str?| follow(Uri uri) {
		// TODO
		return |->Str?| {return null}
	}

	|->Str?| grep(Str pattern, |->Str?| lines) {
		regex := Regex(pattern)
		return |->Str?| {
			Str? line
			while ((line = lines()) != null) {
				if (regex.matcher(line).find()) {
					return line
				}
			}
			return null
		}
	}

	Void main() {
		print(grep(".*pants.*", follow(`/var/log/system.log`)))
	}

	Void print(|->Str?| lines) {
		// Different here the Python version.
		// This directly consumes instead of chaining.
		Str? line
		while ((line = lines()) != null) {
			echo(line)
		}
	}

}
